//
//  PostsTableViewCell.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/4.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "PostsTableViewCell.h"

@implementation PostsTableViewCell
{
    CGFloat moveNum;
    GLGWButton *rightBtn;
    GLGWLabel *detaiLab;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        GLGWImageView *imagV = [[GLGWImageView alloc] initInSuperView:self.contentView];
        [imagV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(kWidthProportion_In_iPhoneTriploid(15)));
            make.top.equalTo(@(kHeightProportion_In_iPhoneTriploid(18)));
            make.width.height.equalTo(@(kWidthProportion_In_iPhoneTriploid(44)));
        }];
        imagV.backgroundColor = [UIColor redColor];
        imagV.layer.masksToBounds = YES;
        imagV.layer.cornerRadius = 22;
        
        GLGWButton *but = [[GLGWButton alloc] initWithTitle:@"300" titleLableFont:SYSTEMFONT(14) titleLableColor:[UIColor colorWithHexString:@"#666666"] inSuperView:self.contentView];
        [but mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@(-kWidthProportion_In_iPhoneTriploid(15)));
            make.top.equalTo(self.contentView);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(60)));
            make.width.greaterThanOrEqualTo(@(50));
//            make.left.equalTo(@(kWidthProportion_In_iPhoneTriploid(320)));
        }];
        [but setImage:[UIImage imageNamed:@"goods_share"] forState:UIControlStateNormal];
        [but setImagePositionWithType:SSImagePositionTypeLeft spacing:5];
        but.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [but setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        rightBtn = but;
        
        GLGWButton *btn2 = [[GLGWButton alloc] initWithTitle:@"300" titleLableFont:SYSTEMFONT(14) titleLableColor:[UIColor colorWithHexString:@"#666666"] inSuperView:self.contentView];
        [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(but.mas_left).offset(-21);
            make.centerY.equalTo(but.mas_centerY);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(40)));
            make.width.greaterThanOrEqualTo(@(50));
        }];
        [btn2 setImage:[UIImage imageNamed:@"goods_share"] forState:UIControlStateNormal];
        [btn2 setImagePositionWithType:SSImagePositionTypeLeft spacing:5];
        [btn2 setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        btn2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;

        GLGWLabel *label = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:kColor_Rule_Black inSuperView:self.contentView];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
            make.left.equalTo(imagV.mas_right).offset(kWidthProportion_In_iPhoneTriploid(10));
            make.right.mas_lessThanOrEqualTo(btn2.mas_left).offset(-kWidthProportion_In_iPhoneTriploid(6));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
        }];
        [label setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
        label.text = @"陈也";
        
        GLGWLabel *label2 = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#999999"] inSuperView:self.contentView];
        [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(label.mas_left);
            make.top.equalTo(label.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(4));
            make.width.equalTo(label.mas_width);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(17)));
        }];
        label2.text = @"2018-09-25 12:00";
        //
        GLGWLabel *label3 = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:kColor_Rule_Black inSuperView:self.contentView];
        [label3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(imagV.mas_left);
            make.top.equalTo(imagV.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(15));
            make.right.equalTo(@(-kWidthProportion_In_iPhoneTriploid(15)));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(40)));
        }];
        label3.text = @"混沌创业营新一期开始招生，想上得可以来找我推荐在这里交来找我推荐在这里交来找我推荐到很多良师益友，是幸福也是一辈子得财富。";
        label3.numberOfLines = 2;
        detaiLab = label3;
        
        self.selectionStyle = UITableViewCellSelectionStyleBlue;
        UIView *seleView = [[UIView alloc] init];
        seleView.backgroundColor = [UIColor clearColor];
        self.selectedBackgroundView = seleView;
        self.multipleSelectionBackgroundView = seleView;
    }
    return self;
}

- (void)setSelectedBackgroundView:(UIView *)selectedBackgroundView
{
    selectedBackgroundView.backgroundColor = [UIColor clearColor];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    if (!self.editing) {
        return;
    }
    [super setSelected:selected animated:animated];
    
    if (self.editing) {
//        arLabel.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
    }
    self.tintColor = [UIColor colorWithHexString:@"#A89A60"];
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
    [super setEditing:editing animated:animated];
    if (editing) {
        [self customMultipleChioce];
    }else{
        [self customMultiple];
    }
}

- (void)customMultipleChioce{
    moveNum = kWidthProportion_In_iPhoneTriploid(40);
    [self updateMasonry];
    [UIView animateWithDuration:0.3 animations:^{
        [self layoutIfNeeded];
    }];
}
- (void)customMultiple
{
    moveNum = 0;
    [self updateMasonry];
    [UIView animateWithDuration:0.3 animations:^{
        [self layoutIfNeeded];
    }];
}

- (void)updateMasonry
{
    [rightBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-kWidthProportion_In_iPhoneTriploid(15) + self->moveNum));
    }];
    [detaiLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-kWidthProportion_In_iPhoneTriploid(15) + self->moveNum));
    }];
}

@end
